<?php
/**
*  Our second controller controllers/test/test2.php
*/
Class Test_2 extends Controller
{
    public $sample_var  = 'you can use $this->variable from view';    
    public $sample_var2 = 'you can use $this->variable from model';   

    function __construct()
    {
        parent::__construct();
        parent::__user();
        
        loader::app_lib('mylibrary');
    }                               
    
    function index()
    {
        // Default Connection from config file  
        //------------------- db ----------------------//
        
        loader::database();       // default static connection
              
        $this->db->query('SELECT * FROM articles');
        $result = $this->db->all(assoc);
        
        print_r($result);
        echo '<br /><br />';
        
        // Custom Connection from config file  
        //------------------- db2 ----------------------//
        
        loader::database('db2');  // second static connection
        
        $this->db2->query('SELECT * FROM tr_users');
        $result2 = $this->db2->all(assoc);
        
        print_r($result2);
        echo '<br /><br />'; 
        
        // Dynamic custom connection
        //------------------- db3 ----------------------//
        
        $params = array(         
            'variable' => 'db3', // this->db3
            'hostname' => 'localhost',
            'username' => 'root',
            'password' => '',
            'database' => 'nested_model',
            'dbdriver' => 'mysql',
            'dbh_port' => '',
            'char_set' => 'utf8',
        );
        
        loader::database($params); // manual dynamic connection with params
        
        $this->db3->query('SELECT * FROM category');
        $result3 = $this->db3->all(assoc);
        
        print_r($result3);
        echo '<br /><br />';
        
    }

        
} //end of the class.
  
  
?>
